﻿@model WebCalendar.Models.DTOs.ManageCalendarRolesDTO

@{
    ViewBag.Title = "CalendarRoles";
     
}

<h2>Role management</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Roles</legend>

        @Html.HiddenFor(model => model.Calendar.ID)
        <div>
            <table>
                <tr>
                    <th>User name</th>
                    <th>Role</th>
                    <th>Action</th>
                </tr>
                <tr>

                    <td>
                        @Html.EditorFor(model => model.NewUser)
                    </td>
                    <td>
                        @Html.DropDownListFor(m => Model.NewRole, Model.AvailableRoles.Select(m => new SelectListItem { Text = m, Value = m }))
                    </td>
                    <td></td>
                    <td>
                        <input type="submit" value="Add" />
                    </td>
                </tr>

                @foreach (var item in Model.Users)
                {
                    <tr>

                        <td>
                            @Html.Label(item.User.UserName)
                        </td>
                        <td>
                            @Html.Label(item.RoleName)
                        </td>
                        <td>
                            @{if (item.RoleName == "Editor")
                            {
                                @Html.ActionLink("Demote", "Demote", "Manage", new { id = Model.Calendar.ID, roleId = item.RoleId },null)
                            }
                            else
                            {
                                @Html.ActionLink("Promote", "Promote", "Manage", new { id = Model.Calendar.ID, roleId = item.RoleId },null)
                            }
                            }
                        </td>
                        <td>
                            @Html.ActionLink("Remove", "RemoveRole", "Manage", new { id = Model.Calendar.ID, roleId = item.RoleId },null)
                        </td>
                    </tr>
                }
            </table>
        </div>

    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

}


